package com.gupaoedu.mybatis.gp.config;

import com.gupaoedu.mybatis.gp.plugin.Interceptor;
import com.gupaoedu.mybatis.gp.plugin.InterceptorChain;
import lombok.Data;

import java.util.List;

/**
 * Created by James on 2017-07-01.
 * From 咕泡学院出品
 * 老师咨询 QQ 2904270631
 */
@Data
public class GpConfiguration {

    private String scanPath;

    private MapperRegistory mapperRegistory = new MapperRegistory();
    private InterceptorChain interceptorChain;

    public GpConfiguration(InterceptorChain interceptorChain) {
        this.interceptorChain = interceptorChain;
    }

    public GpConfiguration scanPath(String scanPath) {
        this.scanPath = scanPath;
        return this;
    }

    public void build() throws Exception {
        if (null == scanPath || scanPath.length() < 1) {
            throw new RuntimeException("scan path is required .");
        }
        List<String> interceptorList = MapperRegistory.interceptorList;
        for (String interceptorName:interceptorList) {
            interceptorChain.addInterceptor((Interceptor) Class.forName(interceptorName).newInstance());
        }
    }

    public static void main(String[] args) throws Exception {
//        new GpConfiguration().scanPath("com/gupaoedu/mybatis/gp/config/mappers").build();
    }
}
